package com.mobilebsc.datatype;

import org.json.JSONException;
import org.json.JSONObject;

public class WeakSignal {

	private int id;
	private String name;
	private String description;
	private String source;

	/**
	 * Constructor for empty weak signals
	 */
	public WeakSignal() {
		this.id = -1;
		this.name = "null";
		this.description = "null";
		this.source = "null";
	}

	/**
	 * Use constructor to create weak signal from JSONObject
	 * 
	 * @param weakSignalJSON
	 * @throws JSONException
	 */
	public WeakSignal(JSONObject weakSignalJSON) throws JSONException {
		this.id = weakSignalJSON.getInt("id");
		this.name = weakSignalJSON.getString("name");
		this.description = weakSignalJSON.getString("description");
		this.source = weakSignalJSON.getString("source");
	}

	public WeakSignal(int id, String name, String description, String source) {
		super();
		this.id = id;
		this.name = name;
		this.description = description;
		this.source = source;
	}

	/**
	 * Use for instancing a new WeakSignal from UI: id is set by database
	 * 
	 * @param name
	 * @param description
	 * @param source
	 */
	public WeakSignal(String name, String description, String source) {
		super();
		this.id = 0;
		this.name = name;
		this.description = description;
		this.source = source;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * Returns weak signal as a JSONObject
	 * 
	 * @return
	 * @throws JSONException
	 */
	public JSONObject getJSON() throws JSONException {
		JSONObject json = new JSONObject();

		json.put("id", getId());
		json.put("name", getName());
		json.put("description", getDescription());
		json.put("source", getSource());

		return json;
	}
}